package pro.softzhang.algo.lc100;

import pro.softzhang.algo.flag.knowledge.KBinarySearch;
import pro.softzhang.algo.flag.theme.TRotatedSortedArray;

/**
 * 153. 寻找旋转排序数组中的最小值
 * https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array
 */
@TRotatedSortedArray
public class LC153_FindMinimumInRotatedSortedArray {
    public static void main(String[] args) {

    }

    @KBinarySearch
    static
    class Solution {
        public int findMin(int[] nums) {
            int n = nums.length;
            int left = -1, right = n - 1;
            while (left + 1 < right) {
                int middle = left + (right - left) / 2;
                if (nums[middle] < nums[n - 1]) {
                    right = middle;
                } else {
                    left = middle;
                }
            }
            return nums[right];
        }
    }
}
